//获取应用实例

const app = getApp();
const date = new Date();
Page({
  data: {
    isWin:false,
    isOld:true,
    language:app.globalData.lang,
    isIphoneX:app.globalData.isIphoneX,
    air:{temp:26,type:'',api:0,quality:''},
    airType:'',
    airTypeArr:{
      晴:'Sunny',
      多云:'Cloudy',
      阴:'Overcast',
      阵雨:'Shower',
      雷阵雨: 'Thunder shower' ,
      雷阵雨伴有冰雹: 'Thunder shower with hail',
      雨夹雪:'rain and snow',
      小雨:'Light rain',
      中雨:  'Moderate rain',
      大雨:  'Heavy rain',
      暴雨:  'Torrential rain',
      大暴雨: 'Heavy torrential rain',
      特大暴雨:  'Extraordinary torrential rain',
      阵雪:  'Snow shower',
      小雪:  'Light snow' ,
      中雪:  'Moderate snow',
      大雪: 'Heavy snow',
      暴雪:  'Heavy snowfall',
      雾: 'Fog',
      冻雨:  'Freezing rain',
      沙尘暴: 'Sand storm',
      '小雨-中雨': 'Light rain-moderate rain',
      '中雨-大雨': 'Moderate rain-heavy rain',
      '大雨-暴雨': 'Heavy rain-torrential rain',
      '暴雨-大暴雨':  'Torrential rain-heavy torrential rain',
      '大暴雨-特大暴雨':  'Heavy torrential rain-extraordinary torrential rain',
      '小雪-中雪': 'Light snow-moderate snow',
      '中雪-大雪': 'Moderate snow-heavy snow',
      '大雪-暴雪': 'Heavy snow-heavy snow fall',
      浮尘:  'Dust',
      扬沙:  'Sand blowing',
      强沙尘暴:  'Strong sand storm',
      霾: 'Smog'
    },
    month: (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1),
    day:date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
    week:date.getDay(),
    weekDate:{zh:{1:'星期一',2:'星期二',3:'星期三',4:'星期四',5:'星期五',6:'星期六',0:'星期日'},
              en:{1:'Mon',2:'Tue',3:'Wed',4:'Thu',5:'Fri',6:'Sat',0:'Sun'}},
    weekText:'',
    switch: 'zh',
    current: 'jinbo',
    jinbo: '逛进博',
    shanghai: '逛上海',
    grids: {},
    lang: {},
    x:0,
    y:0,
    z:0,
    lLogo:'/images/voice_z.png',
    border:false,
    windowWidth:0,
    windowHeight:0,
    popupTitle:'',
    publicTitle:'',
    indicatorDots: false,
    autoplay: true,
    interval: 5000,
    duration: 5000,
    circular:true,
    alphaData:null,
  },
  onLoad: function() {
    const systemInfo=wx.getSystemInfoSync();
    var that = this;
    this.data.lang = require('../../utils/index.js');
    if (app.globalData.lang == 'zh') {
      this.setData({
        isOld: app.globalData.isOldSDK,
        switch: 'zh',
        weekText:this.data.weekDate.zh[this.data.week],
        grids: this.data.lang.zh.jinbo.grids,
        jinbo: this.data.lang.zh.jinbo.guang,
        shanghai: this.data.lang.zh.shanghai.guang,
        x:systemInfo.windowWidth-65,
        y:systemInfo.windowHeight-120,
        windowWidth:systemInfo.windowWidth,
        windowHeight:systemInfo.windowHeight,
        lLogo: this.data.lang.zh.logo,
      });
    } else {
      this.setData({
        switch: 'en',
        weekText:this.data.weekDate.en[this.data.week],
        grids: this.data.lang.en.jinbo.grids,
        jinbo: this.data.lang.en.jinbo.guang,
        shanghai: this.data.lang.en.shanghai.guang,
        x:systemInfo.windowWidth-65,
        y: systemInfo.windowHeight - 120,
        lLogo: this.data.lang.en.logo,
      });
    }
    wx.request({
      url:app.globalData.url+'index/index',
      method:'POST',
      success:function(res){
        that.setData({
            air:res.data.data,
            airType:res.data.data.type,
            publicTitleZh:res.data.data.publicTitleZh,
            publicTitleEn:res.data.data.publicTitleEn,
            publicTitle:res.data.data.publicTitleZh
        });
      }
    });
  },
  hideWin:function(){
    this.setData({
      isWin: false,
    });
  },
  public:function(e){
    wx.navigateTo({
      url:"/pages/sub/pages/public/index"
    });
  },
  loadSuc:function(e){
    console.log("成功调用");
    console.log(e);
    this.setData({
      isWin: true,
    });
  },
  loadErr:function(e){
    console.log("调用失败");
    this.setData({
      isWin: false,
    });
  },
  popup:function(e){
    const method=e.currentTarget.dataset.method;
    const url=e.currentTarget.dataset.url;
    const label=e.currentTarget.dataset.label;
    switch(method)
    {
      case 'navigateTo':{
        wx.navigateTo({
          url:url,
          fail:function(e){
            console.log(e);
          }
        });
      }break
      case 'popup':{
            this.setData({
              popupTitle:url
            });
      }break
      case 'h5':{
        var title = '';
        switch(label){
          case "展会介绍": { const ID = 1; title = app.globalData.lang == 'zh' ? '前往官方网站中' :'前往官方网站中';}break
          case "馆内指引": { const ID = 1; title = app.globalData.lang == 'zh' ? '前往官方网站中' : '前往官方网站中';}break
          case "新闻报道": { const ID = 1; app.globalData.lang == 'zh' ? '前往官方网站中' : '前往官方网站中';}break
          case "网上展厅": { const ID = 1; app.globalData.lang == 'zh' ? '前往官方网站中' : '前往官方网站中';}break
          case "美食": { const ID = 1; title = app.globalData.lang == 'zh' ? '寻找人气美食中' : '寻找人气美食中';}break
          case "住宿": { const ID = 1; title = app.globalData.lang == 'zh' ? '寻找人气美食中' : '寻找人气美食中';}break
          case "娱乐": {
            const ID = 1; title = app.globalData.lang == 'zh' ? '寻找休闲娱乐中' : '寻找休闲娱乐中';}break
          case "馆内指引": { const ID = 1; title = app.globalData.lang == 'zh' ? '正在为您定位中' : '正在为您定位中';}break
        }
        wx.navigateTo({
          url: '/pages/h5/index?url=' + encodeURIComponent(url) + '&title='+title
        })
      }break
      case 'phone':{
        wx.makePhoneCall({
          phoneNumber:url
        });
      } break
      case 'xcx': {
        wx.navigateToMiniProgram({
          appId: url,
        });
      } break
      default:{
        wx.showToast({
            title: '此功能暂未开放，请持续关注！',
            icon: 'none',
            duration: 2000
        })
      }
    }
  },
  clickVoice:function(){
    // wx.showToast({
    //   title: '此功能暂未开放，请持续关注！',
    //   icon: 'none',
    //   duration: 2000
    // })
    // return;
    wx.navigateToMiniProgram({
      appId: 'wxb1070eabc6f9107e',
      // version:'develop',
    });
  },
  goCiie:function(e){
    this.setData({
      popupTitle:''
    });
    wx.navigateTo({
          url:'/pages/shanghai/qujinbo/index',
          fail:function(e){
            console.log(e);
          }
        });
  },
  borderShow:function(e){
    console.log(e);
    this.setData({
      border:true,
      z:2,
    });
  },
  borderHidden:function(e){
    console.log(e);
    this.setData({
      border:false,
      z:0,
    });
  },
  //切换语言
  languageChange(event) {
    if(app.globalData.lang=='en'){
      app.globalData.lang = 'zh';
      this.data.air.type=this.data.airType;
      this.setData({
        language:'zh',
        switch: 'zh',
        air:this.data.air,
        weekText:this.data.weekDate.zh[this.data.week],
        current: this.data.current,
        shanghai: this.data.lang.zh.shanghai.guang,
        jinbo: this.data.lang.zh.jinbo.guang,
        grids: 'jinbo' == this.data.current ? this.data.lang.zh.jinbo.grids : this.data.lang.zh.shanghai.grids,
        lLogo: this.data.lang.zh.logo,
        publicTitle:this.data.publicTitleZh
      });
    } else {
      app.globalData.lang = 'en';
      this.data.air.type=this.data.airTypeArr[this.data.airType];
      this.setData({
        language:'en',
        switch: 'en',
        air:this.data.air,
        weekText:this.data.weekDate.en[this.data.week],
        current: this.data.current,
        shanghai: this.data.lang.en.shanghai.guang,
        jinbo: this.data.lang.en.jinbo.guang,
        grids: 'jinbo' == this.data.current ? this.data.lang.en.jinbo.grids : this.data.lang.en.shanghai.grids,
        lLogo: this.data.lang.en.logo,
        publicTitle:this.data.publicTitleEn,
      });
    };
  },
  //切换九宫格数据
  handleChange(detail) {
    //重新获取grids数据
    var guang = detail.currentTarget.id;
    switch (guang) {
      case 'jinbo':
        {
          this.setData({
            current: guang,
            grids: 'zh' == app.globalData.lang ? this.data.lang.zh.jinbo.grids : this.data.lang.en.jinbo.grids
          });
        }
        break;
      case 'shanghai':
        {
          this.setData({
            current: guang,
            grids: 'en' == app.globalData.lang ? this.data.lang.en.shanghai.grids : this.data.lang.zh.shanghai.grids
          });
        }
        break;
    }
  },
  moveTap(){
    console.log('点击了图层');
  },
  callPhone(){
    wx.makePhoneCall({
      phoneNumber: "+86-21-968888"
    });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
    return {
      title: app.globalData.shareTitle,
      path: app.globalData.sharePath,
      imageUrl: '../../images/share_img.png',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },

})